﻿@page "/Bas/Goods/Details"
@using nERP.ViewModel.Bas.GoodsVMs
@using System.ComponentModel.DataAnnotations
@inherits BasePage

<div>
    <ValidateForm @ref="vform" Model="@Model" OnValidSubmit="@Submit">
        <Row ItemsPerRow="ItemsPerRow.Three" RowType="RowType.Normal">
            <Display @bind-Value="@Model.Entity.GoodsCode" ShowLabel="true" />
            <Display @bind-Value="@Model.Entity.GoodsName" ShowLabel="true" />
            <Display @bind-Value="@Model.Entity.GoodsSpec" ShowLabel="true" />
            <Display @bind-Value="@Model.Entity.GoodsTypeId" ShowLabel="true" Lookup="AllGoodsTypes" />
            <Display @bind-Value="@Model.Entity.GoodsUnitId" ShowLabel="true" Lookup="AllGoodsUnits" />
            <Display @bind-Value="@Model.Entity.RestockingPrice" ShowLabel="true" />
            <Display @bind-Value="@Model.Entity.RetailPrice" ShowLabel="true" />
            <Display @bind-Value="@Model.Entity.WholesalePrice" ShowLabel="true" />
            <Display @bind-Value="@Model.Entity.SafetyStock" ShowLabel="true" />
            <Display @bind-Value="@Model.Entity.Remark" ShowLabel="true" />
            <WTUploadImage @bind-Value="@Model.Entity.GoodsImages" thumb-width="128" />
            <Display @bind-Value="@Model.Entity.Stock" ShowLabel="true" />
            <Display @bind-Value="@Model.Entity.CreateTime" ShowLabel="true" FormatString="yyyy-MM-dd HH:mm:ss" />
            <Display @bind-Value="@Model.Entity.UpdateTime" ShowLabel="true" FormatString="yyyy-MM-dd HH:mm:ss" />
            <Display @bind-Value="@Model.Entity.CreateBy" ShowLabel="true" />
            <Display @bind-Value="@Model.Entity.UpdateBy" ShowLabel="true" />
            <Display @bind-Value="@Model.Entity.IsValid" ShowLabel="true" />
        </Row>

        <div class="modal-footer table-modal-footer">
            <Button OnClick="OnClose" Text="@WtmBlazor.Localizer["Sys.Close"]" />
        </div>

    </ValidateForm>

</div>



@code {
    [Parameter]
    public string id { get; set; }
    [Parameter]
    public string[] ids { get; set; }
    private GoodsVM Model = new GoodsVM();
    private ValidateForm vform { get; set; }
    private async Task Submit(EditContext context)
    {


        await PostsForm(vform, "/api/Bas/Goods/Edit", (s) => "Sys.OprationSuccess");
    }
    public void OnClose()
    {
        CloseDialog();
    }

    private List<SelectedItem> AllGoodsTypes = new List<SelectedItem>();
    private List<SelectedItem> AllGoodsUnits = new List<SelectedItem>();
    protected override async Task OnInitializedAsync()
    {


        AllGoodsTypes = await WtmBlazor.Api.CallItemsApi("/api/Bas/Goods/GetGoodsClasss");
        AllGoodsTypes.Insert(0, new SelectedItem { Text = WtmBlazor.Localizer["Sys.PleaseSelect"], Value = "" });
        AllGoodsUnits = await WtmBlazor.Api.CallItemsApi("/api/Bas/Goods/GetComputationUnits");
        AllGoodsUnits.Insert(0, new SelectedItem { Text = WtmBlazor.Localizer["Sys.PleaseSelect"], Value = "" });
        if (id != "")
        {
            var rv = await WtmBlazor.Api.CallAPI<GoodsVM>($"/api/Bas/Goods/{id}");
            Model = rv.Data;
        }

        await base.OnInitializedAsync();
    }
}
